import 'package:gold/generated/json/base/json_convert_content.dart';
import 'package:gold/model/commission_list_model.dart';

CommissionListModel $CommissionListModelFromJson(Map<String, dynamic> json) {
  final CommissionListModel commissionListModel = CommissionListModel();
  final List<CommissionModel>? data = (json['data'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<CommissionModel>(e) as CommissionModel).toList();
  if (data != null) {
    commissionListModel.data = data;
  }
  final int? total = jsonConvert.convert<int>(json['total']);
  if (total != null) {
    commissionListModel.total = total;
  }
  final int? count = jsonConvert.convert<int>(json['count']);
  if (count != null) {
    commissionListModel.count = count;
  }
  final int? perPage = jsonConvert.convert<int>(json['per_page']);
  if (perPage != null) {
    commissionListModel.perPage = perPage;
  }
  final int? currentPage = jsonConvert.convert<int>(json['current_page']);
  if (currentPage != null) {
    commissionListModel.currentPage = currentPage;
  }
  final int? totalPages = jsonConvert.convert<int>(json['total_pages']);
  if (totalPages != null) {
    commissionListModel.totalPages = totalPages;
  }
  return commissionListModel;
}

Map<String, dynamic> $CommissionListModelToJson(CommissionListModel entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['data'] = entity.data?.map((v) => v.toJson()).toList();
  data['total'] = entity.total;
  data['count'] = entity.count;
  data['per_page'] = entity.perPage;
  data['current_page'] = entity.currentPage;
  data['total_pages'] = entity.totalPages;
  return data;
}

extension CommissionListModelExtension on CommissionListModel {
  CommissionListModel copyWith({
    List<CommissionModel>? data,
    int? total,
    int? count,
    int? perPage,
    int? currentPage,
    int? totalPages,
  }) {
    return CommissionListModel()
      ..data = data ?? this.data
      ..total = total ?? this.total
      ..count = count ?? this.count
      ..perPage = perPage ?? this.perPage
      ..currentPage = currentPage ?? this.currentPage
      ..totalPages = totalPages ?? this.totalPages;
  }
}

CommissionModel $CommissionModelFromJson(Map<String, dynamic> json) {
  final CommissionModel commissionModel = CommissionModel();
  final int? id = jsonConvert.convert<int>(json['id']);
  if (id != null) {
    commissionModel.id = id;
  }
  final String? nickname = jsonConvert.convert<String>(json['nickname']);
  if (nickname != null) {
    commissionModel.nickname = nickname;
  }
  final String? avatar = jsonConvert.convert<String>(json['avatar']);
  if (avatar != null) {
    commissionModel.avatar = avatar;
  }
  final double? amount = jsonConvert.convert<double>(json['amount']);
  if (amount != null) {
    commissionModel.amount = amount;
  }
  final String? status = jsonConvert.convert<String>(json['status']);
  if (status != null) {
    commissionModel.status = status;
  }
  final int? orderId = jsonConvert.convert<int>(json['order_id']);
  if (orderId != null) {
    commissionModel.orderId = orderId;
  }
  final String? settledAt = jsonConvert.convert<String>(json['settled_at']);
  if (settledAt != null) {
    commissionModel.settledAt = settledAt;
  }
  final String? canceledAt = jsonConvert.convert<String>(json['canceled_at']);
  if (canceledAt != null) {
    commissionModel.canceledAt = canceledAt;
  }
  final String? createdAt = jsonConvert.convert<String>(json['created_at']);
  if (createdAt != null) {
    commissionModel.createdAt = createdAt;
  }
  final CommissionOrderModel? order = jsonConvert.convert<CommissionOrderModel>(json['order']);
  if (order != null) {
    commissionModel.order = order;
  }
  return commissionModel;
}

Map<String, dynamic> $CommissionModelToJson(CommissionModel entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['id'] = entity.id;
  data['nickname'] = entity.nickname;
  data['avatar'] = entity.avatar;
  data['amount'] = entity.amount;
  data['status'] = entity.status;
  data['order_id'] = entity.orderId;
  data['settled_at'] = entity.settledAt;
  data['canceled_at'] = entity.canceledAt;
  data['created_at'] = entity.createdAt;
  data['order'] = entity.order?.toJson();
  return data;
}

extension CommissionModelExtension on CommissionModel {
  CommissionModel copyWith({
    int? id,
    String? nickname,
    String? avatar,
    double? amount,
    String? status,
    int? orderId,
    String? settledAt,
    String? canceledAt,
    String? createdAt,
    CommissionOrderModel? order,
  }) {
    return CommissionModel()
      ..id = id ?? this.id
      ..nickname = nickname ?? this.nickname
      ..avatar = avatar ?? this.avatar
      ..amount = amount ?? this.amount
      ..status = status ?? this.status
      ..orderId = orderId ?? this.orderId
      ..settledAt = settledAt ?? this.settledAt
      ..canceledAt = canceledAt ?? this.canceledAt
      ..createdAt = createdAt ?? this.createdAt
      ..order = order ?? this.order;
  }
}

CommissionOrderModel $CommissionOrderModelFromJson(Map<String, dynamic> json) {
  final CommissionOrderModel commissionOrderModel = CommissionOrderModel();
  final String? orderNo = jsonConvert.convert<String>(json['order_no']);
  if (orderNo != null) {
    commissionOrderModel.orderNo = orderNo;
  }
  final int? quantity = jsonConvert.convert<int>(json['quantity']);
  if (quantity != null) {
    commissionOrderModel.quantity = quantity;
  }
  final double? payPrice = jsonConvert.convert<double>(json['pay_price']);
  if (payPrice != null) {
    commissionOrderModel.payPrice = payPrice;
  }
  final String? productName = jsonConvert.convert<String>(json['product_name']);
  if (productName != null) {
    commissionOrderModel.productName = productName;
  }
  return commissionOrderModel;
}

Map<String, dynamic> $CommissionOrderModelToJson(CommissionOrderModel entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['order_no'] = entity.orderNo;
  data['quantity'] = entity.quantity;
  data['pay_price'] = entity.payPrice;
  data['product_name'] = entity.productName;
  return data;
}

extension CommissionOrderModelExtension on CommissionOrderModel {
  CommissionOrderModel copyWith({
    String? orderNo,
    int? quantity,
    double? payPrice,
    String? productName,
  }) {
    return CommissionOrderModel()
      ..orderNo = orderNo ?? this.orderNo
      ..quantity = quantity ?? this.quantity
      ..payPrice = payPrice ?? this.payPrice
      ..productName = productName ?? this.productName;
  }
}